/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package diningphilosopher;

/**
 *
 * @author TQNINH
 */
public class ChopStick {
    boolean available;
    
    public ChopStick(){
        available = true;
    }
    
    public synchronized void takeup(){
        while(!available){
            try{
                System.out.println("Philosopher is waiting for the other chopstick");
                wait();
            } catch(InterruptedException e) {
                e.printStackTrace();
            }
        }
        available = false;
    }
    
    public synchronized void putdown(){
        available = true;
        notify();
    }
}
